home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / dir-ops.h < prev    next >
C/C++ Source or Header  |  1996-11-10  |  2KB  |  91 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_dir_ops_h)
  24. #define octave_dir_ops_h 1
  25.  
  26. #include <string>
  27.  
  28. #include "str-vec.h"
  29.  
  30. class
  31. dir_entry
  32. {
  33. public:
  34.  
  35.   dir_entry (const string& n = string ()) : name (n), dir (0)
  36.     {
  37.       if (! name.empty ())
  38.         open ();
  39.     }
  40.  
  41.   dir_entry (const dir_entry& d) { copy (d); }
  42.  
  43.   dir_entry& operator = (const dir_entry& d)
  44.     {
  45.       if (this != &d)
  46.     copy (d);
  47.  
  48.       return *this;
  49.     }
  50.  
  51.   ~dir_entry (void) { close (); }
  52.  
  53.   bool open (const string& = string ());
  54.  
  55.   string_vector read (void);
  56.  
  57.   void close (void);
  58.  
  59.   bool ok (void) const { return dir && ! fail; }
  60.  
  61.   operator void* () const { return ok () ? (void *) -1 : (void *) 0; }
  62.  
  63.   string error (void) const { return ok () ? string () : errmsg; }
  64.  
  65. private:
  66.  
  67.   // Name of the directory.
  68.   string name;
  69.  
  70.   // A pointer to the contents of the directory.  We use void here to
  71.   // avoid possible conflicts with the way some systems declare the
  72.   // type DIR.
  73.   void *dir;
  74.  
  75.   // TRUE means the open for this directory failed.
  76.   bool fail;
  77.  
  78.   // If a failure occurs, this contains the system error text.
  79.   string errmsg;
  80.  
  81.   void copy (const dir_entry&);
  82. };
  83.  
  84. #endif
  85.  
  86. /*
  87. ;;; Local Variables: ***
  88. ;;; mode: C++ ***
  89. ;;; End: ***
  90. */
  91.